<template>
  <!-- html -->
  <div class="person">
    <h2>姓名:{{ person.name }}</h2>
    <h2>年龄:{{ person.age }},{{ age1 }}</h2>
    <button @click="changeName">修改名字</button>
    <button @click="changeAge">修改年龄</button>
  </div>
</template>

<script lang="ts" setup name="Person">
import { reactive, toRefs, toRef } from "vue";

let person = reactive({
  name: "zs",
  age: 18,
});
//加了toRefs name 和 age 都是ref  reactive对象 --> 一个个ref对象
let { name, age } = toRefs(person);
let age1 = toRef(person, "age");
//与person中的数据有关联
function changeName() {
  name.value += "~";
}
function changeAge() {
  age.value += 1;
}
</script>

<style scoped>
/* 样式 */
.person {
  background-color: skyblue;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
button {
  margin: 0 5px;
}
</style>
